#!/usr/bin/env python

import os
import time

source = ['/usr/whq/codeRepository']
targetDir = '/usr/whq/backup'

if not os.path.exists(targetDir):
	os.mkdir(targetDir)

targetFile = targetDir + os.sep + time.strftime("%Y%m%d%H%M%S") + ".tar.gz"
tarCommand = "tar czf " + targetFile + ' ' + ' '.join(source)

print ( tarCommand )

if os.system(tarCommand) == 0:
	print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
	print('Successful backup to ' + targetFile)
else:
	print('Backup failed')
